package com.yanqu.road.server.cmd.assistant;

import com.yanqu.road.entity.beautyescort.EscortBeautyDispatch;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.assistant.AssistantProto;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.assistant.CrossAssistantMgr;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manager.palace.CrossPalaceActivity;
import com.yanqu.road.server.manager.palace.CrossPalaceActivityMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = CrossProtocol.C_ESCORT_ASSISTANT_ACTION, desc = "押镖 小助理操作")
public class CrossEscortAssistantActionCmd extends CrossCommand {

    private long userId;
    List<EscortBeautyDispatch> dispatchList;
    private AssistantProto.AssistantCrossActionReqMsg crossMsg;
    UserBaseInfo userBaseInfo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        crossMsg = AssistantProto.AssistantCrossActionReqMsg.parseFrom(packet.getBytes());
        dispatchList = CrossBeautyEscortMgr.parseBeautyDispatch(crossMsg.getBeautyList());
        userId = packet.getPlayerId();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(crossMsg.getUserInfo());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        AssistantProto.AssistantActionReqMsg.Builder assistantActionReqMsg = crossMsg.getAssistantActionReqMsg().toBuilder();
        AssistantProto.AssistantActionRespMsg.Builder assistantActionRespMsg = crossMsg.getAssistantActionRespMsg().toBuilder();
        // 未派遣美女
        List<EscortBeautyDispatch> noDispatchList = new ArrayList<>();
        // 自动押镖
        CrossAssistantMgr.autoDispatchDart(assistantActionRespMsg, serverId, userId, dispatchList, noDispatchList, userBaseInfo);
        AssistantProto.AssistantCrossActionRespMsg.Builder builder = AssistantProto.AssistantCrossActionRespMsg.newBuilder();
        builder.setAssistantActionReqMsg(assistantActionReqMsg);
        builder.setAssistantActionRespMsg(assistantActionRespMsg);
        builder.addAllNoDispatchList(CrossBeautyEscortMgr.parseBeautyDispatchBuilderList(noDispatchList));
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_ASSISTANT_ESCORT_ACTION_FROM_CROSS, builder);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {
    }
}
